//
//  LcRequestCenter.h
//  18Birdies
//
//  Created by Lc on 15/3/23.
//  Copyright (c) 2015年 Lc. All rights reserved.
//

#import <Foundation/Foundation.h>

#import "LcSingleton.h"

@class LcRequestMeta;
@class LcRequestData;
@class LcResponseData;
@class LcApiError;

typedef void (^SuccessHandler)(__kindof LcRequestData* requestData,
                               id responseData,
                               NSData* aesKey);
typedef void (^ApiErrorHandler)(__kindof LcRequestData* requestData,
                                LcApiError* apiError);
typedef void (^NetworkErrorHandler)(__kindof LcRequestData* requestData, NSError* error);

@interface LcRequestCenter : LcSingleton

- (void)registerBaseUrl:(NSString*)baseUrl;
- (void)registerRequestMeta:(LcRequestMeta*)requestMeta;

- (void)registerCommonHeaders:(NSDictionary*)commonHeaders;

- (void)registerAesIv:(NSString*)aesIv;
- (void)registerCommonAesKey:(NSData*)commonAesKey;
- (void)registerRsaKey:(NSString*)rsaKey;
// set after user login, clear after user logout; pass nil to clear
- (void)registerUserAesKey:(NSData*)userAesKey
               clientToken:(NSString*)clientToken;

// all handlers are called on the main thread
- (void)sendRequest:(LcRequestData*)requestData
     successHandler:(SuccessHandler)successHandler
    apiErrorHandler:(ApiErrorHandler)apiErrorHandler
networkErrorHandler:(NetworkErrorHandler)networkErrorHandler;

- (void)registerCommonApiErrorHandler:(ApiErrorHandler)apiErrorHandler;
- (void)registerCommonNetworkErrorHandler:
    (NetworkErrorHandler)networkErrorHandler;

- (NSData*)userAesKey;

@end
